package com.cristina.attention.rest;

import com.cristina.attention.entity.Message;
import com.cristina.attention.mp.support.Condition;
import com.cristina.attention.service.MessageService;
import com.cristina.attention.utils.Func;
import com.cristina.attention.utils.R;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author by superman
 * @Date 2021/12/9
 */
@Slf4j
@RestController
@RequestMapping("core/message")
@AllArgsConstructor
public class MessageController {

    private final MessageService messageService;

    /**
     * 查询单条
     * @param message
     * @return
     */
    @ApiOperation(value = "查看详情", notes = "传入id")
    @GetMapping("/detail")
    public R<Object> detail(Message message) {
        Message detail = messageService.getOne(Condition.getQueryWrapper(message));
        return R.data(detail);
    }

    /**
     * 查询单条
     */
    @ApiOperation(value = "查看详情", notes = "传入id")
    @GetMapping("/info")
    public R<Object> info(Message message) {
        Message detail = messageService.getById(message.getMessageId());
        return R.data(detail);
    }

    @GetMapping("/list")
    @ApiOperation(value = "列表")
    public R<Object> list() {
        return R.data(messageService.list());
    }

    /**
     * 新增或修改
     */
    @ApiOperation(value = "新增或修改", notes = "传入groupVo")
    @PostMapping("/submit")
    public R<Object> submit(@RequestBody Message message) {
        return R.status(messageService.save(message));
    }

    /**
     * 修改
     */
    @ApiOperation(value = "修改", notes = "传入groupVo")
    @PostMapping("/update")
    public R<Object> update(@RequestBody Message message) {
        return R.status(messageService.updateById(message));
    }

    /**
     * 删除
     */
    @ApiOperation(value = "删除", notes = "传入groupId")
    @PostMapping("/remove")
    public R<Object> remove(@PathVariable String messageId) {
        return R.status(messageService.deleteLogic(Func.toLongList(messageId)));
    }

    @ApiOperation(value = "同步消息记录", notes = "传入message", hidden = true)
    @PostMapping("/syncSimpleMessageRecord")
    public R<Object> syncSimpleMessageRecord(@RequestBody String message) {
        messageService.syncSimpleMessageRecord(message);
        return R.status(true);
    }

    @ApiOperation(value = "同步消息记录", notes = "传入message", hidden = true)
    @PostMapping("/syncGroupMessageRecord")
    public R<Object> syncGroupMessageRecord(@RequestBody String message) {
        messageService.syncGroupMessageRecord(message);
        return R.status(true);
    }
}
